package com.kikt.animationdemo;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.kikt.animationdemo.fragment.ViewpagerFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by kikt on 2016/1/16.
 */
public class ViewPagerActivity extends FragmentActivity {

    public static final String IMG_URL = "imgUrl";
    Context mContext = this;
    protected FrameLayout mRootView;
    protected FragmentManager fm;
    @Bind(R.id.fl_container)
    FrameLayout mFlContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        ButterKnife.bind(this);
        fm = getSupportFragmentManager();
        addFragment(new ViewpagerFragment());
    }

    public void addFragment(Fragment fragment) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fl_container, fragment);
        ft.commit();
    }

    public static class MyAdapter extends PagerAdapter {

        private Context mContext;

        public MyAdapter(Context mContext) {
            this.mContext = mContext;
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView view = new ImageView(mContext);
            view.setImageResource(R.drawable.like_icon0);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }
}
